<?php

class HomeAction extends Action {

    /**
     * -----房产版本
     */
    public function index(){

        $Model = new Model();

        $Model->db("1","DB_fy_house");

        //随机品牌
        //$StrSqlGCRan = "Select top 9  NewID() as random, ClassID,ClassName,Zimu,Logo From Group_Class Where ParentID='0' order by NewID()";
        //$DataGcRan = $Model->query( $StrSqlGCRan );

        //推荐品牌
        //$StrSqlGCHot = "Select top 6 ClassID,ClassName,Zimu,Logo From Group_Class Where ParentID='0' and istop = '1'";
        //$DataGcHot = $Model->query( $StrSqlGCHot );

        //幻灯片5条
        $StrSqlArtTJ = "Select top 5 id,html,title,Spic1,linkurl from fy_info where (Spic1 is not null) and Slide='1' and area_name='".C("APP_URL_AREA")."' and CharIndex('.',spic1)>0  order by id desc";
        $DataArtTJ = $Model->query( $StrSqlArtTJ );



        //3条头条
        $StrSqlArtTJRed = "SELECT TOP 2 *,CONVERT(varchar(100), InputDate, 120) as InputDate FROM vInfo WHERE (TID = 37) AND (Strip = 1) and area_name='".C("APP_URL_AREA")."'  ORDER BY tjph DESC ,ID DESC";
        $DataArtTJRed = $Model->query( $StrSqlArtTJRed );

        //3条新闻
        $SqlArtXw = "SELECT TOP 2 *,CONVERT(varchar(100), InputDate, 120) as InputDate FROM vInfo WHERE (TID = 37) AND (Strip = 0) and area_name='".C("APP_URL_AREA")."'  ORDER BY tjph DESC ,ID DESC";
        $DataArtXw = $Model->query( $SqlArtXw );

        //今日推荐数组合并
        $DareTodayNews =  array_merge($DataArtTJRed, $DataArtXw);


        //精品楼盘
        $SqlJPHouse = "Select top 4 Hid,HouseName,simg,avgprice,liyou,wylx,zgj,BeginPrice,AvgPrice,zgjUnit,BeginPriceUnit,AvgPriceUnit From newhouse where tj='1' and area_name='".C("APP_URL_AREA")."' and tjph > 20000 order by tjph desc, Hid desc";

        $DataJPHouse = $Model->query( $SqlJPHouse );

        foreach ( $DataJPHouse  as & $value ) {
            $value['smallimg']  =  getNewHousePic($value['simg']) ;
            $value['jg']  = getPrice(4,$value['wylx'],$value['zgj'],$value['BeginPrice'],$value['AvgPrice']);
        }

        $Model->db("2","Db_Sxol_Home");

        //样板间
        $SqlYbj = "select top 4 ID,YbjName, Miniature,Images, NewID() as random from home_Ybj order by random desc";
        $DataYbj = $Model->query( $SqlYbj );
        $this->assign('DataArtTJ',$DataArtTJ);
        $this->assign('DareTodayNews',$DareTodayNews);
        $this->assign('DataJPHouse',$DataJPHouse);
        $this->assign('DataYbj',$DataYbj);
        //$this->assign('DataGcRan',$DataGcRan);
        $this->display();
    }

    /**
     * ----- 信息换一换
     * @param $type
     * @param int $classid
     * @param $page
     * @param int $pageSize
     */
    public function  changeList($type,$classid = 0,$page,$pageSize = 4){
        switch ( $type ) {
            //最新咨询
            case "zxzx":case "lsgd":case "lsdt":
                $Model = new Model();
                $Model->db("1","DB_fy_house");
                $Strzxzx = "select top 4 *,CONVERT(varchar(100), InputDate, 120) as InputDate, NewID() as random from (SELECT TOP 30  * FROM vInfo WHERE (TID = '".$classid."') AND (Strip = 0) and area_name='".C("APP_URL_AREA")."'  ORDER BY tjph DESC ,ID DESC ) as tmp where 1=1 order by random";
                $DataZxzx = $Model->query( $Strzxzx );

                $DataZxzx =$this->searchArt($classid,$pageSize,$page,"");

                if ($DataZxzx){
                    $this->ajaxReturn($DataZxzx,"查询成功！",1,'JSON');
                }else{
                    $this->ajaxReturn(0,"没有数据了！",0,'JSON');
                }
                break;
            case  "jplp" :

                $DatalptjHouse =  $this->searchHouse("","","",0,12000000,$pageSize,$page," and tj='1' and area_name='".C("APP_URL_AREA")."' and tjph > 20000 "," order by tjph desc, Hid desc ");

                foreach ( $DatalptjHouse  as & $value ) {
                    $value['smallimg']  =  getNewHousePic($value['simg']) ;
                    $value['jg']  = getPrice(4,$value['wylx'],$value['zgj'],$value['BeginPrice'],$value['AvgPrice']);
                }

                if ($DatalptjHouse){
                    $this->ajaxReturn($DatalptjHouse,"查询成功！",1,'JSON');
                }else{
                    $this->ajaxReturn(0,"没有数据了！",0,'JSON');
                }

                break;
            case  "zjkp" :

                $DatazxkpHouse = $this->searchHouse("","","",0,12000000,$pageSize,$page," and area_name='".C("APP_URL_AREA")."' and tjph <20000 "," ORDER BY tjph desc,Dateandtime DESC ");

                foreach ( $DatazxkpHouse  as & $value ) {
                    $value['smallimg']  =  getNewHousePic($value['simg']) ;
                    $value['jg']  = getPrice(4,$value['wylx'],$value['zgj'],$value['BeginPrice'],$value['AvgPrice']);
                }

                if ($DatazxkpHouse){
                    $this->ajaxReturn($DatazxkpHouse,"查询成功！",1,'JSON');
                }else{
                    $this->ajaxReturn(0,"没有数据了！",0,'JSON');
                }
                break;
            case "rxlp":
                $DatazxkpHouse = $this->searchHouse("","","",0,12000000,$pageSize,$page," and sh='1' and area_name='".C("APP_URL_AREA")."'  "," order by n_y desc,n_m desc,sale_num desc,hid desc ");

                foreach ( $DatazxkpHouse  as & $value ) {
                    $value['smallimg']  =  getNewHousePic($value['simg']) ;
                    $value['jg']  = getPrice(4,$value['wylx'],$value['zgj'],$value['BeginPrice'],$value['AvgPrice']);
                }

                if ($DatazxkpHouse){
                    $this->ajaxReturn($DatazxkpHouse,"查询成功！",1,'JSON');
                }else{
                    $this->ajaxReturn(0,"没有数据了！",0,'JSON');
                }
                break;
            case "ybj":
                $Model = new Model();
                $Model->db("2","Db_Sxol_Home");
                //样板间
                $SqlYbj = "select top 4 ID,YbjName, Miniature,Images, NewID() as random from home_Ybj order by random desc";
                $DataYbj = $Model->query( $SqlYbj );

                if ($DataYbj){
                    $this->ajaxReturn($DataYbj,"查询成功！",1,'JSON');
                }else{
                    $this->ajaxReturn(0,"没有数据了！",0,'JSON');
                }
                break;
            default :
                $ClassName="车讯";
                break;
        }

    }

    /**
     * -----房产文章列表
     * @param $Tid
     * @param int $pageSize
     * @param int $page
     */
    public function homeInfolist($Tid,$pageSize = 20,$page = 0){

        $DataUc = $this-> unClass($Tid);
        if($DataUc ){
            $DataFyInfo = $this->searchArt($Tid,$pageSize,$page);
            //$ClassName = $this->getClassName($Tid);
            $Tname = $DataUc[0]['Tname'];

            $this->assign('Tname',$Tname);
            $this->assign('Tid',$Tid);
            $this->assign('DataFyInfo',$DataFyInfo);
            $this->display();
        }else{
            $this->error('请求的模块不存在！');
        }
    }

    /**
     * ------房产文章搜索
     * @param $Tid
     * @param $keyword
     * @param int $pageSize
     * @param int $page
     */
    public function searArtlist($Tid,$keyword,$pageSize = 20,$page = 0){

        if($Tid != "" || $keyword !=""){

            $DataUa = $this->searchArt($Tid,$pageSize,$page,$keyword);

            $this->assign("keyword",$keyword);
            $this->assign('Tid',$Tid);
            $this->assign('DataUa',$DataUa);
            $this->display();
        }else{
            $this->error('请求的模块不存在！');
        }
    }

    /**
     * -----房产的文章
     * @param $id
     */
    public function  homeInfo($id){

        $Model = new Model(); // 实例化一个model对象 没有对应任何数据表
        $Model->db("1","DB_fy_house");

        $StrSqlFyInfo = "Select fi.*, fc.Tname,CONVERT(varchar(100), fi.InputDate, 120) as InputDate from fy_info fi ,fy_class fc where fi.id='".$id."' and fi.area_name='".C('APP_URL_AREA')."'  and fc.id = fi.tid ";

        $DataFyInfo = $Model->query( $StrSqlFyInfo );

        if ($DataFyInfo){

            //最新的相关的6条
            $StrSqlVInfoNew =  "SELECT TOP 6 * FROM vInfo WHERE TID = '".$DataFyInfo[0]["TID"]."' and area_name='".C('APP_URL_AREA')."'  ORDER BY tjph DESC ,ID DESC";
            $DataVInfoNew= $Model->query( $StrSqlVInfoNew );

            if($DataFyInfo[0]['hid'] != '0'){
                $StrSqlVInfoHouse = "SELECT TOP 6 * FROM vInfo WHERE hid = '".$DataFyInfo[0]['hid']."' and area_name='".C('APP_URL_AREA')."'  ORDER BY tjph DESC ,ID DESC";
                $DataVInfoHouse= $Model->query( $StrSqlVInfoHouse );
                $this->assign('DataVInfoHouse',$DataVInfoHouse);
            }

            $Model->db("0");

            //精彩赏图
            $StrRanFour =  "select top 4 *, NewID() as random from (SELECT top 20 * FROM photo_class where Dth = 3 and area_name = '".C('APP_URL_AREA')."' ORDER BY id desc) pc2 order by random  ";
            $DataRanFour= $Model->query( $StrRanFour );

            $this->assign('Tname',$DataFyInfo[0]["Tname"]);
            $this->assign('Tid',$DataFyInfo[0]["TID"]);
            $this->assign('DataRanFour',$DataRanFour);
            $this->assign('DataVInfoNew',$DataVInfoNew);
            $this->assign('DataFyInfo',$DataFyInfo)  ;
            $this->display();

        }else{
            $this->error('没有找到该文章！');
        }

    }

    /**
     * -----JSONP返回
     * @param $Tid
     * @param $keyword
     * @param int $pageSize
     * @param int $page
     */
    public function search($Tid,$keyword,$pageSize = 10,$page = 0){
        $DataUc = $this -> searchArt($Tid,$pageSize,$page,$keyword);
        if ($DataUc){
            $this->ajaxReturn($DataUc,"查询成功！",1,'JSONP');
        }else{
            $this->ajaxReturn(0,"没有数据了！",0,'JSONP');
        }
    }

    /**
     * -----返回文章的类型
     * @param $Tid
     * @return array|mixed
     */
    public function unClass ($Tid){
        $Model = new Model();
        $Model->db("1","DB_fy_house");
        $StrSqlUc = "select top 1 * from fy_class where id ='".$Tid."'";
        $DataUc = $Model->query( $StrSqlUc );
        return $DataUc;
    }

    /**
     * -----分页返回文章列表
     * @param $Tid
     * @param int $pageSize
     * @param int $page
     * @param string $Keyword
     * @return array|mixed
     */
    public  function  searchArt($Tid,$pageSize = 10,$page = 0,$Keyword = ""){
        $Model = new Model();
        $Model->db("1","DB_fy_house");
        $where = "1 = 1 ";

        if($Tid != ""){
            $where = $where . " and Tid='".$Tid."'";
        }

        if($Keyword != ""){
            $where = $where . " and ( Title Like '%".$Keyword."%' or Keywords Like '%".$Keyword."%' ) ";
        }

        $where = $where . "and area_name='".C("APP_URL_AREA")."'";

        $StrSqlUc = "SELECT * from (select top ".intval($pageSize)*(intval($page)+1)." ID,Title,Spic,CONVERT(varchar(100), InputDate, 120) as DateAndTime from vInfo Where ".$where."  order by ID desc) as art where  art.id not in (select top ".intval($pageSize)*intval($page)." ID from vInfo Where ".$where."  order by ID desc)";

        $DataUc = $Model->query( $StrSqlUc );

        $StrSqlTotal =  "select Count(ID) as count from vInfo Where ".$where;
        $DataToal = $Model->query( $StrSqlTotal );

        $this->assign("DataToal",$DataToal);

        return $DataUc;
    }

    /**
     * -----新房楼盘列表
     */
    public function newhouse($city = "",$wylx = "",$sort = "",$minpr=0,$maxpr=120000,$pageSize = 20,$page = 0){

        if(true ){
            $this->searchHouse($city,$wylx,$sort,$minpr,$maxpr,$pageSize,$page,"","");

            $Model = new Model();
            $Model->db("1","DB_fy_house");

            $StrSqlCity = "SELECT threeid, city FROM fyasp_city WHERE (twoid = '1') and threeid>0 ORDER BY indexid";
            $DataCity = $Model->query( $StrSqlCity );

            foreach ( $DataCity  as & $cityItem ) {
                if($cityItem['threeid'] == $city){
                    $this->assign('city',$cityItem);
                }
            }

            $this->assign('DataCity',$DataCity);
            $this->assign('minpr',intval($minpr));
            $this->assign('maxpr',intval($maxpr));


            $this->display();
        }else{
            $this->error('请求的模块不存在！');
        }
    }

    /**
     *  ----- 关键字搜索楼盘
     * @param $keyword
     */
    public function searchHouseP($keyword){
        if($keyword != ""){
            $DataJPHouse = $this->searchHouse("","","",0,12000000,20,0,"","",$keyword);
            $this->assign('DataJPHouse',$DataJPHouse);
            $this->assign('keyword',$keyword);
            $this->display();
        }else{
            $this->error('关键字错误！');
        }

    }

    /**
     * -----详细楼盘内容
     * @param string $Hid
     */
    public function house($Hid){

        $Model = new Model();
        $Model->db("1","DB_fy_house");

        $StrSqlHouse = "select top 1 * from newhouse where HID=".$Hid." and area_name='".C('APP_URL_AREA')."'";

        $DataHouse = $Model->query( $StrSqlHouse );

        if($DataHouse){
            $DataHouse = $DataHouse[0];

        $indexImg  = array ($this->getTopImg($DataHouse['simg'],'simg'),$this->getTopImg($DataHouse['bimg'],'bimg'),$this->getTopImg($DataHouse['wzimg'],'wzimg'),$this->getTopImg($DataHouse['guihuapic'],'guihuapic'));

        $DataHouse['indexImg'] = $indexImg;
            if($DataHouse['ditu'] == ""){
                $DataHouse['ditu'] = "120.589973,30.003001";
            }

           $HouseImg =  array_merge($this->getImg(split('\@@@',$DataHouse['xqimg'])), $this->getImg(split('\@@@',$DataHouse['fximg'])),$this->getImg(split('\@@@',$DataHouse['slimg'])));

            function findVal($arr,$dir){
                $rsImgArr =  array();
                foreach($arr as $key=>$val){

                    $dirArr = split('\|',$dir);
                    foreach($dirArr as $dirVal){
                        if(strstr($val[0],$dirVal)){
                            array_push($rsImgArr,$val);
                        }
                    }
                }
                return $rsImgArr;
            }
            $DataHouse['xgimgArr'] =  findVal($HouseImg,"效果|小区");
            $DataHouse['hximgArr'] =  findVal($HouseImg,"户型|样板间|室内");
            $DataHouse['sjimgArr'] =  findVal($HouseImg,"实景");
            $DataHouse['qtimgArr'] =  findVal($HouseImg,"配套");



        $StrSqlHouseInfo = "select top 8 Title,id from fy_info where hid='".$Hid."' order by id desc";
        $DataHouseInfo = $Model->query( $StrSqlHouseInfo );

        $this->assign('DataHouseInfo',$DataHouseInfo);
        $this->assign('DataHouse',$DataHouse);

        $this->display();
        }else{
            $this->error('该楼盘不存在');
        }
    }

    /**
     * -----看房报名界面
     */
    public function houseApply($Hid = "" ,$Type = "TFT"){

        if($Type == "TFT"){
            $Model = new Model();
            $Model->db("1","DB_fy_house");
            $StrSqlHouse = "select top 1 * from newhouse where HID=".$Hid." and area_name='".C('APP_URL_AREA')."'";
            $DataHouse = $Model->query( $StrSqlHouse );
            if($DataHouse){
                $this->assign('Type',$Type);
                $this->assign('HID',$DataHouse[0]['HID']);
                $this->assign('HouseName',$DataHouse[0]['HouseName']);
                $this->display();
            }else{
                $this->error('该楼盘不存在');
            }
        }else if($Type == "KFT"){

            $this->assign('HID',"");
            $this->assign('HouseName',"看房团");
            $this->assign('Type',$Type);
            $this->display();
        }



    }

    /**
     * -----看房报名申请
     * @param $buyername
     * @param $tel
     * @param $yusuan
     * @param $loupan
     * @param $loupan_id
     * @param $Type
     */
    public function SomeApply($buyername,$tel,$yusuan,$loupan,$loupan_id,$Type){
        $Model = new Model();
        $Model->db("1","DB_fy_house");

        if($buyername == ""){
            $this->ajaxReturn(0,"姓名不能为空！",0,'JSON');
        }

        if($tel == ""){
            $this->ajaxReturn(0,"电话不能为空！",0,'JSON');
        }

        if($yusuan == ""){
            $this->ajaxReturn(0,"预算不能为空！",0,'JSON');
        }

        if($loupan == ""){
            $this->ajaxReturn(0,"楼盘不能为空！",0,'JSON');
        }


        if($Type == "KFT"){
            $SqlInset = "INSERT INTO baomingtuan (buyername, tel,yusuan,loupan,loupan_id,adddate,area_name,ipaddr,sex) VALUES ('".$buyername."','".$tel."','".$yusuan."','".$loupan."','".$loupan_id."','". date('Y-m-d h:i:s',time())."','绍兴','".get_client_ip()."','0')";
            $Model->execute($SqlInset);
        }else if($Type == "TFT"){
            $SqlInset = "INSERT INTO house_Subject_BaoMing (Name, tel,YiXiang,PostTime,area_name) VALUES ('".$buyername."','".$tel."','".$loupan."','". date('Y-m-d h:i:s',time())."','绍兴')";
            $Model->execute($SqlInset);
        }


        $this->ajaxReturn(0,"报名成功！",1,'JSON');

    }

    /**
     * -----房贷计算器
     */
    public function houseCal(){
        $this->display();
    }

    /**
     * -----样板间
     */
    public function  homeYbj($HXid = 0,$FGid = 0,$pageSize = 10,$page = 0,$Keyword = ""){
        $Model = new Model();
        $Model->db("2","Db_Sxol_Home");
        $StrSqlFg = "select * from home_Ybj_Fg where vis = 1 order by OrderNum,id asc ";
        $DataFg = $Model->query( $StrSqlFg );

        $StrSqlHx = "select * from home_Ybj_Hx where vis = 1 order by OrderNum,id asc ";
        $DataHx = $Model->query( $StrSqlHx );

        $DataYBJ = $this->searchYBJ($HXid,$FGid,$pageSize,$page,$Keyword);

        $this->assign("keyword",$Keyword);
        $this->assign('HXid',$HXid);
        $this->assign('FGid',$FGid);
        $this->assign('DataFg',$DataFg);
        $this->assign('DataHx',$DataHx);
        $this->assign('DataYBJ',$DataYBJ);
        $this->display();

    }

    /**
     * ----- 样板间
     * @param $HXid
     * @param $FGid
     * @param int $pageSize
     * @param int $page
     * @param string $Keyword
     * @return array|mixed
     */
    public function searchYBJ($HXid,$FGid,$pageSize = 10,$page = 0,$Keyword = ""){
            $Model = new Model();
            $Model->db("2","Db_Sxol_Home");
            $where = "1 = 1 ";

            if($HXid != ""&&$HXid != 0){
                $where = $where . " and HxID='".$HXid."'";
            }

            if($FGid != ""&&$FGid != 0){
                $where = $where . " and FgID='".$FGid."'";
            }

            if($Keyword != ""&&$HXid != 0){
                $where = $where . " and YbjName Like '%".$Keyword."%' and YbjName Like '%".$Keyword."%' ";
            }

            $where = $where . "and area_name='www'";

            $StrSqlUc = "SELECT * from (select top ".intval($pageSize)*(intval($page)+1)." ID,YbjName, Miniature,Images from home_Ybj Where ".$where."  order by ID desc) as ybj where  ybj.id not in (select top ".intval($pageSize)*intval($page)." ID from home_Ybj Where ".$where."  order by ID desc)";

            $DataUc = $Model->query( $StrSqlUc );

            $StrSqlTotal =  "select Count(ID) as count from home_Ybj Where ".$where;
            $DataToal = $Model->query( $StrSqlTotal );

            $this->assign("DataToal",$DataToal);

            return $DataUc;

    }

    /**
     * ----- 样板间
     * @param int $HXid
     * @param int $FGid
     * @param int $pageSize
     * @param int $page
     * @param string $Keyword
     */
    public  function searchYBJAjax($HXid = 0,$FGid =0,$pageSize = 10,$page = 0,$Keyword = ""){
        $DataUc = $this -> searchYBJ($HXid ,$FGid ,$pageSize ,$page,$Keyword );
        if ($DataUc){
            $this->ajaxReturn($DataUc,"查询成功！",1,'JSONP');
        }else{
            $this->ajaxReturn(0,"没有数据了！",0,'JSONP');
        }
    }

    /**
     * -----房产图片
     * @param $imgArr
     * @return array
     */
    public function getImg($imgArr){
        $picArr = array();
        foreach($imgArr as $img){
            if($img!=""){
                array_push ($picArr,split('\|',$img));
            }
        }

        return $picArr;
    }

    /**
     * -----获取幻灯图片
     * @param $img
     * @param $imgType
     * @return array
     */
    public function getTopImg($img,$imgType){

        if($img != ""){
            $picArr = split('\|',$img);
            if(count($picArr)>1){
                if($picArr[1]!=""){
                    $picArr =  $picArr;
                }else{
                    $picArr = $this->setImg($imgType,C('HOUSE_NOIMG'));
                }

            }else{
                $picArr = $this->setImg($imgType,$img);
            }
        }else{
            $picArr = $this->setImg($imgType,C('HOUSE_NOIMG'));
        }

        return $picArr;
    }

    /**
     * -----获取幻灯普通
     * @param $imgType
     * @param $imgPath
     * @return array
     */
    public function setImg($imgType,$imgPath){

        if($imgType == "simg"){
            $picArr = array( "效果图" , $imgPath);
        }

        if($imgType == "bimg"){
            $picArr = array( "外景图" , $imgPath);
        }

        if($imgType == "wzimg"){
            $picArr = array( "位置图" , $imgPath);
        }

        if($imgType == "guihuapic"){
            $picArr = array( "实景图" , $imgPath);
        }
        return $picArr;
    }

    /**
     * -----搜索房产楼盘
    */
    public function searchHouse($city = "",$wylx = "",$sort = "",$minpr=0,$maxpr=120000,$pageSize = 20,$page = 0,$cusWhere = "" ,$cusOrder = "",$keyword ="" ){
        $Model = new Model();
        $Model->db("1","DB_fy_house");

        $where = "1 = 1 ";

        if($city != ""){
            $where = $where . "and city_threeid='".$city."'";
        }

        if($wylx != "" && $wylx != 0){
            $stypeArr = C(HOUSE_WYLX);
            $this->assign('wylx',$stypeArr[$wylx]);
            $stype = $stypeArr[$wylx]['VALUE'];
            $where = $where . "and wylx like'".$stype."'";
        }

        if($sort != ""){
            $sortArr = C(HOUSE_SORT);
            $this->assign('sort',$sortArr[$sort]);

            switch ( $sort ) {
                case  0 :
                    $order = " order by BeginPrice desc ";
                    break;
                case  1 :
                    $order = " order by BeginPrice asc ";
                    break;
                case  2 :
                    $order = " order by ctime desc ";
                    break;
                case  3 :
                    $order = " order by ctime asc ";
                    break;
                case  4 :
                    $order = " order by n_y desc,sale_num desc ";
                    break;
                case  5 :
                    $order = " order by n_y desc,sale_num asc ";
                    break;
            }

        }

        if($cusWhere != ""){
            $where = $where.$cusWhere;
        }

        if($cusOrder != ""){
            $order = $cusOrder;
        }

        if($keyword!=""){
            $where = $where." and ( HouseName like '%".$keyword."%' or Developer like '%.$keyword.%' ) ";
        }

        $where = $where. " and ((zgj > ".$minpr." and zgj < ".$maxpr .") or (BeginPrice > ".$minpr ." and BeginPrice < ".$maxpr.") or (AvgPrice > $minpr"." and AvgPrice > ".$minpr."))";

        $where = $where . "and sh='1' and area_name='".C("APP_URL_AREA")."'";

        $StrSqlTotal =  "select count(hid) as count from vNewHouse Where ".$where." ";
        $DataToal = $Model->query( $StrSqlTotal );

        $StrSqlNewHouse = "SELECT * from (select top ".intval($pageSize)*(intval($page)+1)." hid,sale_num,sale_ts,n_m, HouseName, wylx,zgj,BeginPrice,AvgPrice,simg,kpsj,BeginPriceUnit,AvgPriceUnit,zgjUnit,city_three from vNewHouse Where ".$where.$order." ) as newh where  newh.hid not in (select top ".intval($pageSize)*intval($page)." hid from vNewHouse Where ".$where.$order." )";

        $DataNewHouse = $Model->query( $StrSqlNewHouse );

        foreach ( $DataNewHouse  as & $value ) {
            $value['smallimg']  =  getNewHousePic($value['simg']) ;
            $value['jg']  = getPrice(4,$value['wylx'],$value['zgj'],$value['BeginPrice'],$value['AvgPrice']);
        }


        $this->assign('DataToal',$DataToal);
        $this->assign('DataNewHouse',$DataNewHouse);

        return $DataNewHouse;
    }

    /**
     * -----搜索房产楼盘JSONP返回
     */
    public function searchHouseJsonp($city = "",$wylx = "",$sort = "",$minpr=0,$maxpr=100000,$pageSize = 20,$page = 0){
        $DataUc = $this -> searchHouse($city,$wylx,$sort,$minpr,$maxpr,$pageSize,$page,"","");
        if ($DataUc){
            $this->ajaxReturn($DataUc,"查询成功！",1,'JSONP');
        }else{
            $this->ajaxReturn(0,"没有数据了！",0,'JSONP');
        }
    }

}